using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace TX
{
    public partial class Login2 : Base
    {
        string Username, InitialPassword;
        public Login2(string Username, string InitialPassword)
        {
            InitializeComponent();
            this.Username = Username;
            this.InitialPassword = InitialPassword;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (textEdit1.Text == InitialPassword && textEdit2.Text == textEdit3.Text)
            {
                string[] PH = SaltedHashing.Hash(textEdit2.Text, textEdit3.Text);

                using (SqlConnection con = new SqlConnection(Properties.Settings.Default.Karbel4ConnectionString))
                {
                    con.Open();
                    SqlCommand cmd2 = new SqlCommand("update Contact set PasswordHash = @PasswordHash, PasswordSalt = @PasswordSalt where Username=@Username", con);
                    cmd2.Parameters.AddWithValue("@Username", Username);
                    cmd2.Parameters.AddWithValue("@PasswordHash", PH[1]);
                    cmd2.Parameters.AddWithValue("@PasswordSalt", PH[0]);
                    int affected = cmd2.ExecuteNonQuery();
                }

                this.DialogResult = DialogResult.OK;
            }
        }


    }
}